﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace ch01
{
    public partial class FrmAddSutInfo : Form
    {
        public FrmAddSutInfo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name = this.txt_name.Text;
            string pwd = this.txt_pwd.Text;
            string drpwd = this.txt_drpwd.Text;
            string sex = this.radioButton1.Checked ? "男" : "女";
            int gradeId = Convert.ToInt32(this.comboBox1.SelectedValue);
            string phone = this.txt_phone.Text;
            string adderss = this.txt_address.Text;
            string date = this.dateTimePicker1.Value.ToString("yyyy-MM-dd");
            string email = this.txt_Email.Text;
            if (string.IsNullOrEmpty(name)||string.IsNullOrEmpty(pwd))
            {
                MessageBox.Show("您输入的信息不完整！");
               
                return;
            }
            if (!pwd.Equals(drpwd))
            {
                MessageBox.Show("您输入的密码不一致！");
                return;
            }
            string sql = string.Format(@"insert into Student 
           values('{0}','{1}','{2}',{3},'{4}','{5}','{6}','{7}')",
             pwd, name, sex, gradeId, phone, adderss, date, email);
            int reader = DBHelper.DataUpdate(sql);
            if (reader > 0)
            {
                MessageBox.Show("添加成功！");
            }
            else
            {
                MessageBox.Show("添加失败！");
            }
        }
     
        private void FrmAddSutInfo_Load(object sender, EventArgs e)
        {
            string sql = "select * from Grade";
            DataTable dt = DBHelper.SelectTable(sql);
            this.comboBox1.DisplayMember = "Gradename";
            this.comboBox1.ValueMember = "no";
            this.comboBox1.DataSource = dt;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.txt_name.Text = this.txt_pwd.Text = this.txt_drpwd.Text = this.txt_phone.Text=
           this.txt_drpwd.Text = this.txt_Email.Text = this.txt_address.Text = string.Empty;
            this.comboBox1.SelectedIndex = 0;
            this.radioButton1.Checked = true;
            this.dateTimePicker1.Value = DateTime.Now;

        }
    }
}
